package com.beasts.antpage.sh.controller;

import com.beasts.antpage.sh.entity.APPagePortlet;
import com.beasts.antpage.sh.entity.Layout;
import com.beasts.antpage.sh.service.ILayoutService;
import com.beasts.antpage.sh.service.IPagePortletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiOperation;
//import springfox.documentation.annotations.ApiIgnore;

/**
 * 布局管理器
 *
 * @author Locker
 * @date 18/04/2018 6:59 PM
 * @since 1.0
 */
//@Api(value = "/layout", tags = "布局管理器")
@Controller
@RequestMapping("/layout")
public class LayoutManagerController {

    @Autowired
    private ILayoutService layoutService;

    @Autowired
    private IPagePortletService pagePortletService;

//    /**
//     * 获取指定布局管理 器
//     *
//     * @param type 请求参数，指定管理器类型，默认 react，可选 bootstrap
//     * @return
//     */
////    @ApiOperation(value = "布局管理器配置页", notes = "实现自定义布局")
////    @ApiImplicitParam(name = "type", value = "布局管理器类型，默认 react，可选 bootstrap", dataType = "String")
//    @GetMapping("/manager")
//    public String layoutManagerIndex(@RequestParam(value = "type", required = false, defaultValue = "Bootstrap") String type,HttpServletRequest req) {
//        return "subpage/layout/layoutManager" + StringUtil.toUpperCaseFirstOne(type);
//    }

    @GetMapping("/findAllLayoutName")
    @ResponseBody
    public List<String> findAllLayoutName() {
        return layoutService.findAllLayoutName();
    }

//    @ApiIgnore
    @RequestMapping("/saveLayout")
    @ResponseBody
    public String saveLayout(HttpServletRequest req) {
        String pageId = req.getParameter("pageId");
        String name = req.getParameter("name");
        String html = req.getParameter("html");
        String editHtml = req.getParameter("editHtml");
        return layoutService.saveLayout(pageId,name, html,editHtml);
    }

    /**
     * 测试
     */
//    @ApiOperation(value = "测试页面，当前默认展示指定页面")
    @GetMapping("/testNewPage")
    public String testNewPage() {
        return "subpage/layout/layoutShow";
    }

    /**
     * 加载指定名称的页面代码
     */
    @GetMapping("/findLayoutHtml")
    @ResponseBody
    public String findLayoutHtml(@RequestParam("pageId") String pageId) {
        return layoutService.findLayoutHtml(pageId);
    }

    /**
     * 删除指定页面
     */
    @RequestMapping("/deleteLayoutHtml")
    @ResponseBody
    public Map<String, String> deleteLayoutHtml (@RequestParam("pageId") String pageId) {
        layoutService.deleteLayoutHtml(pageId);
        return null;
    }
    /**
     * 获取指定页面
     */
    @RequestMapping("/getLayoutHtml")
    @ResponseBody
    public Layout getLayoutHtml (@RequestParam("pageId") String pageId) {

        return layoutService.findLayoutById(pageId);

    }
    /**
     * 检索布局频道
     */
    @RequestMapping("/getPagePortletByPageId")
    @ResponseBody
    public List<APPagePortlet> getPagePortletByPageId (HttpServletRequest req) {
        String pageId = req.getParameter("pageId");
        return pagePortletService.getPagePortletByPageId(pageId);
    }
    /**
     * 保存布局频道
     */
    @RequestMapping("/savePagePortlet")
    @ResponseBody
    public Boolean savePagePortlet (HttpServletRequest req) {
        String pageId = req.getParameter("pageId");
        String pageName = req.getParameter("pageName");
        String layoutId = req.getParameter("layoutId");
        String portletId = req.getParameter("portletId");
        String portletName = req.getParameter("portletName");
        return pagePortletService.savePagePortlet(pageId,pageName,layoutId,portletId,portletName);
    }

    /**
     * 删除布局频道
     */
    @RequestMapping("/deletePagePortlet")
    @ResponseBody
    public Boolean deletePagePortlet (HttpServletRequest req) {
        String pageId = req.getParameter("pageId");
        pagePortletService.deletePagePortlet(pageId);
        return true;
    }



}
